<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>
    	<spring:message code="head.clothGarment"></spring:message>-
    	<spring:message code="login.forgotPassword"></spring:message>
    </title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/web/css/NormalizeFile.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/web/css/public.css">
    <!--登录注册忘记密码三个页面的样式-->
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/web/css/subpage/login.css">
</head>
<body class="loginbody">
<div class="contenter mt134">
    <a href="${pageContext.request.contextPath }/web/main/index" onfocus="blur()">
    	<img class="loginlogo" src="${pageContext.request.contextPath }/web/img/logo.png">
    </a>
    <span class="helis-login"><spring:message code="messageForget"></spring:message><a href="${pageContext.request.contextPath}/web/member/login" style="color: #ff0000;"><spring:message code="login"></spring:message></a></span>
<h2 class="logintitle"><spring:message code="fp"></spring:message></h2>
    <!--中间内容部分begin-->
    <div class="logincase">
         <form id="ForgetForm" action="javascript:void(0)">
         <input type="hidden" name="language" value="1">
             <div>
                 <input id="telphone" name="telphone" class="form-control" placeholder="<spring:message code="forgotPassword.enterPhone"></spring:message>" type="text" aria-required="true" aria-invalid="true" onkeyup="value=value.replace(/[^\d]/g,'')" maxlength="11" minlength="11">
             </div>
             <div class="resend-code">
                 <input type="text" id="validateCode" name="validateCode" class="required form-control" placeholder="<spring:message code="forgotPassword.code"></spring:message>"/>
                 <input class="TestGetCode" type="button" value="<spring:message code="forgotPassword.getCode"></spring:message>" onclick="getforcode(this);" />
             </div>
             <div>
                 <input id="password" name="password" class="form-control" onkeyup="value=value.replace(/[^A-Z a-z 0-9]/,'')" placeholder="<spring:message code="forgotPassword.newPassword"></spring:message>" type="password" maxlength="15" minlength="6">
             </div>
             <div>
                 <input id="confirm_password" name="confirm_password" class="form-control" onkeyup="value=value.replace(/[^A-Z a-z 0-9]/,'')" placeholder="<spring:message code="forgotPassword.confirmPassword"></spring:message>" type="password" maxlength="15" minlength="6">
             </div>
             <button type="submit" class="submit"><spring:message code="rp"></spring:message></button>
        </form>
    </div>
    <!--中间内容部分end-->
</div>
<!--footer begin-->
<div class="footer">
    <div class="contenter">
        <div class="footer-left">
            <div class="footer-logo-left">
            <img class="" src="${pageContext.request.contextPath }/web/img/logored.png">
            </div>
            <div class="footer-logo-right"><p><spring:message code="fashion"></spring:message></p><p><spring:message code="material"></spring:message></p></div>
            <div class="clearfix"></div>
            <div class="copyright">
                <p>Copyright 2016 <spring:message code="web"></spring:message></p>
                <p>www.sxbdyz.com All Right Reserved.</p>
                <p><spring:message code="record"></spring:message></p>
            </div>
        </div>
        <div class="footer-center">
            <div class="footer-center-left">
                <a href="javascript:void(0);"><p><spring:message code="memberCenter"></spring:message></p></a>
                <a href="javascript:void(0);"><p><spring:message code="watchlist"></spring:message></p></a>
                <a href="javascript:void(0);"><p><spring:message code="contact"></spring:message></p></a>
            </div>
            <div class="footer-center-right">
                <a href="javascript:void(0);"><p><spring:message code="copyright"></spring:message></p></a>
                <a href="javascript:void(0);"><p><spring:message code="price"></spring:message></p></a>
                <a href="javascript:void(0);"><p><spring:message code="network"></spring:message></p></a>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="footer-right">
            <div class="footer-right-left">
                <p><spring:message code="download"></spring:message></p>
                <img src="${pageContext.request.contextPath }/web/img/code.png">
            </div>
            <div class="footer-right-right">
                <p><spring:message code="public"></spring:message></p>
                <img src="${pageContext.request.contextPath }/web/img/code2.png">
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<!--footer end-->
<!--全局-->
<script type="text/javascript" src="${pageContext.request.contextPath }/web/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/web/js/public.js"></script>
<!--ie789下placeholder不兼容-->
<script type="text/javascript" src="${pageContext.request.contextPath }/web/js/placeholder.js"></script>
<!-- jQuery Validation plugin javascript   表单验证-->
<script type="text/javascript" src="${pageContext.request.contextPath }/web/js/plugins/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/web/js/plugins/validate/messages_zh.min.js"></script>
<!--登录注册忘记密码三个页面的js-->
<%-- <script type="text/javascript" src="${pageContext.request.contextPath }/web/js/subpage/login.js"></script> --%>
<script type="text/javascript">
var icon = "*";
// 手机号码验证
jQuery.validator.addMethod("isMobile", function(value, element) {
	var length = value.length;
	var mobile = /^1[3|4|5|7|8][0-9]\d{4,8}$/;
	return this.optional(element) || (length == 11 && mobile.test(value));
}, '<spring:message code="forgotPassword.correctPhone"></spring:message>');
//以下为忘记密码页面
$("#ForgetForm").validate({
    rules: {
        telphone:{
        	required: true,
            number:true,
            minlength: 11,
            maxlength: 11,
            isMobile : true,
            remote: {
				url: "/bdyz/web/logIn/isTelRegister",
				cache: false
			}
        },
        validateCode:{
            required: true
        },
        password: {
        	required: true,
            minlength: 6,
            maxlength: 15
        },
        confirm_password: {
        	required: true,
        	minlength: 6,
            maxlength: 15,
            equalTo: "#password"
        }
    },
    messages: {
        telphone:{
        	required: icon + '<spring:message code="forgotPassword.enterPhone"></spring:message>',
            number:icon +'<spring:message code="forgotPassword.validNumber"></spring:message>',
            minlength:icon +'<spring:message code="forgotPassword.enter11Digits"></spring:message>',
            maxlength:icon +'<spring:message code="forgotPassword.enter11Digits"></spring:message>',
            isMobile:icon +'<spring:message code="forgotPassword.phoneFormatError"></spring:message>',
            remote:icon +'<spring:message code="forgotPassword.beenRegistered"></spring:message>'
        },
        validateCode:{
          required:icon+'<spring:message code="forgotPassword.enterCode"></spring:message>'
        },
        password: {
        	required: icon + '<spring:message code="forgotPassword.enterPassword"></spring:message>',
            minlength: icon + '<spring:message code="forgotPassword.password6To15"></spring:message>',
            maxlength: icon + '<spring:message code="forgotPassword.password6To15"></spring:message>'
        },
        confirm_password: {
        	required: icon + '<spring:message code="forgotPassword.rePassword"></spring:message>',
        	minlength: icon + '<spring:message code="forgotPassword.password6To15"></spring:message>',
            maxlength: icon + '<spring:message code="forgotPassword.password6To15"></spring:message>',
            equalTo: icon + '<spring:message code="forgotPassword.rePasswordNot"></spring:message>'
        }
    },
	submitHandler: function(form) {
		forgetPassword();
	}
})

//忘记密码
function forgetPassword(){
	$.ajax({
		url: '/bdyz/web/logIn/forgotPassword',
		type:'POST',
		data:$("#ForgetForm").serialize(),
		success:function(result){
			if(result ==1){
				layer.msg('<spring:message code="forgotPassword.passwordReset"></spring:message>',{icon:1,time:1000});
				window.setTimeout("window.location.href='/bdyz/web/member/login'",2000);
			}else if(result ==-1){
				layer.msg('<spring:message code="forgotPassword.errorCode"></spring:message>',{icon:0,time:1000});
			}else if(result ==2){
				layer.msg('<spring:message code="forgotPassword.noRegister"></spring:message>',{icon:0,time:1000});
			}else{
				layer.msg('<spring:message code="forgotPassword.fail"></spring:message>',{icon:0,time:1000});
			}
		}
	});
}

//忘记密码发送验证码
var countdown = 60;
function getforcode(obj) {
	var tel=$("#telphone").val();
	if(tel!=null&&tel!=""){
		var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
		 if (tel.length!=11||!reg.test(tel)) {
			layer.msg('<spring:message code="forgotPassword.phoneFormatError"></spring:message>',{icon:0,time:1000});
			$("#telphone").focus();
			return false; 
		 }
		$.ajax({
    		url: '/bdyz/web/logIn/isTelRegister',
    		type:'POST',
    		data:{telphone:tel},
    		async : false,
    		success:function(result){
    			if(!result){
    				layer.msg("<spring:message code="forgotPassword.enterAgain"></spring:message>！",{icon:0,time:1000});
    				$("#telphone").focus();
    				return false;
    			}else{
    				$.ajax({
    		    		url: '/bdyz/web/logIn/getcode',
    		    		type:'POST',
    		    		data:{telphone:tel},
    		    		success:function(result){
    		    			if(result.msg.status==1){
    		    				layer.msg("<spring:message code="forgotPassword.sendSuccess"></spring:message>！",{icon:1,time:1000});
    		    			}else{
    		    				layer.msg("<spring:message code="forgotPassword.sendFail"></spring:message>！",{icon:0,time:1000});
    		    			}
    		    		}
    		    	});
    				settime(obj);
    			}
    		}
    	});
	}else{
		layer.msg('<spring:message code="forgotPassword.enterPhone"></spring:message>',{icon:0,time:1000});
		$("#telphone").focus();
		return false;
	}
}

//倒计时
function settime(obj) {
	if (countdown == 0) {
        obj.removeAttribute("disabled");
        obj.value = '<spring:message code="forgotPassword.getCode"></spring:message>';
        countdown = 60;
        return;
    } else {
        obj.setAttribute("disabled", true);
        obj.value = "<spring:message code="forgotPassword.resend"></spring:message>(" + countdown + ")";
        countdown--;
    }
    setTimeout(function () {settime(obj)}, 1000)
}

</script>
</body>
</html>